package com.ymf.weibo.action;

import java.util.ArrayList;
import java.util.List;

import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.client.HTablePool;

import com.ymf.weibo.hbase.RelationsDAO;
import com.ymf.weibo.hbase.TwitsDAO;
import com.ymf.weibo.hbase.UsersDAO;
import com.ymf.weibo.model.Twit;
import com.ymf.weibo.model.User;

public class IndexAction extends BaseAction{
	private static final long serialVersionUID = 1L;
	List<String> follow;
	RelationsDAO relationsDao;
	List<Twit> twits;
	
	TwitsDAO twitsDao;
	List<String> unfollow;
	UsersDAO userDao;
	
	public IndexAction(){
		userDao = new UsersDAO(new HTablePool(HBaseConfiguration.create(), 10));
		twitsDao = new TwitsDAO(new HTablePool(HBaseConfiguration.create(), 10));
		relationsDao = new RelationsDAO(new HTablePool(HBaseConfiguration.create(), 10));
		follow = new ArrayList<String>();
		unfollow = new ArrayList<String>();
		twits = new ArrayList<Twit>();
	}

	public String execute() throws Exception{
		if(login_user.equals(""))
			return SUCCESS;
		follow = relationsDao.listFollowsId(login_user);
		List<User> all = userDao.getUsers();
		
		for (User user : all) {
			if(!follow.contains(user.user))
				unfollow.add(user.user);
		}
		
		twits = twitsDao.list(login_user);
		
		System.out.println(follow.size());
		return SUCCESS;
	}

	public List<String> getFollow() {
		return follow;
	}

	public List<Twit> getTwits() {
		return twits;
	}

	public List<String> getUnfollow() {
		return unfollow;
	}

	public void setFollow(List<String> follow) {
		this.follow = follow;
	}

	public void setTwits(List<Twit> twits) {
		this.twits = twits;
	}
	
	public void setUnfollow(List<String> unfollow) {
		this.unfollow = unfollow;
	}

	
}